<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>
        个人信息
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/assets/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/assets/admin/css/xadmin.css}">
    <script th:src="@{/assets/admin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/assets/admin/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
               <input type="text" class="layui-input" disabled id="username" name="username" th:value="${user!=null?user.username:''}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red"></span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" lay-verify="required"
                       autocomplete="off" class="layui-input" th:value="${user!=null?user.name:''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>性别
            </label>
            <div class="layui-input-inline">
                <input type="radio" name="sex" value="男" title="男" th:checked="${user == null?'':user.sex} eq '男'"/>
                <input type="radio" name="sex" value="女" title="女" th:checked="${user == null?'':user.sex} eq '女'"/>
                <input type="radio" name="sex" value="保密" title="保密" th:checked="${user == null?'':user.sex} eq '保密'"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="email" class="layui-form-label">
                <span class="x-red">*</span>邮箱地址
            </label>
            <div class="layui-input-inline">
                <input type="text" id="email" name="email" required="" lay-verify="email"
                       autocomplete="off" class="layui-input" th:value="${user == null?'':user.email}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-inline">
                <input type="text" name="profileUrl" lay-verify="required" id="profileUrl" placeholder="图片地址" th:value="${user == null?'':user.profileUrl}" class="layui-input">
                <button class="layui-btn layui-btn-primary" id="editimg" lay-submit lay-filter="editimg">修改图片</button>
            </div>
            <div class="layui-input-inline">
                <img  id="srcimgurl" class="layui-upload-img" th:src="${user == null?'':user.profileUrl}">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button class="layui-btn" lay-filter="add" lay-submit>
                更新
            </button>
        </div>
    </form>
</div>
<script th:replace="systemCommon/HarinCommon :: commonJs"></script>
<script>
    layui.config({
        base: '/assets/admin/lib/layui/mods/'
    }).extend({
        croppers : "cropper/croppers"
    });

    layui.use(['form', 'layer','croppers'], function () {
        $ = layui.jquery;
        form = layui.form;
        layer = layui.layer;
        croppers = layui.croppers;

        //创建一个头像上传组件
        croppers.render({
            elem: '#editimg'
            ,saveW:150     //保存宽度
            ,saveH:150
            ,mark:1/1    //选取比例
            ,area:'500px'  //弹窗宽度
            ,url: "/user/uploadFIle"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            ,done: function(url){ //上传完毕回调
                $("#profileUrl").val(url);
                $("#srcimgurl").attr('src',url);
            }
        });


        //监听提交
        form.on('submit(editimg)', function (data) {
            return false;
        });
        //监听提交
        form.on('submit(add)', function (data) {
            //console.log(typeof data.field);
            var status = data.field.status;
            if("on" == status){
                data.field.status = 1;
            }else{
                data.field.status = 0;
            }
            //console.log(data);
            //发异步，把数据提交给后台处理
            $.ajax({
                url: "/user/update",
                data: JSON.stringify(data.field),
                type: "post",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    //console.log(data.message);
                    if (data.code == 200) {
                        layer.alert(data.message, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(data.message, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>

</body>

</html>